package framework.account;

import framework.customer.ICustomer;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;


public abstract class AAccount extends Observable implements IAccount {
    public AAccount(String type, String accountNumber) {
        this.type = type;
        this.accountNo = accountNumber;
        balance = 100;
    }

    protected String type;
    protected String accountNo;
    protected float balance;
    protected ICustomer customer;

    private List<IEntry> transactionHistory;


    public void addTransaction(IEntry tr) {
        if (transactionHistory == null) {
            transactionHistory = new ArrayList<IEntry>();
        }
        transactionHistory.add(tr);
        setChanged();
        this.notifyObservers(tr);
    }


    public String getAccountNo() {
        return accountNo;
    }

    private double prevBalance = 0d;


    public float getBalance() {
        return balance;
    }

    public ICustomer getCustomer() {
        return customer;
    }

    public void setCustomer(ICustomer customer) {
        this.customer = customer;
    }

    public double getPrevBalance() {
        return prevBalance;
    }

    public void setPrevBalance(double prevBalance) {
        this.prevBalance = prevBalance;
    }

    public String getType() {
        return type;
    }

    public List<IEntry> getTransactionHistory() {
        return transactionHistory;
    }

    public void addInterest() {
        balance += balance * getInterestRate();
    }


    public boolean processTransaction(float amount) {
        balance += amount;
        return true;
    }


}